package objects;

import java.io.File;

import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.PlatformUI;

public final class AdapletConstants
{
	public enum ColumnType {
		INT, REAL, STRING, DATE, LONG, RAW, LARGESTRING
	}

	public static final String sNewLine = System.getProperty("line.separator");

	public static final String sFileSeparator = File.separator;

	public static final String convertTypeToString(ColumnType typeForColumn)
	{
		switch (typeForColumn)
		{
		case INT:
			return "int";
		case REAL:
			return "real";
		case STRING:
			return "string";
		case DATE:
			return "date";
		case LONG:
			return "long";
		case RAW:
			return "raw";
		case LARGESTRING:
			return "largestring";
		default:
			return "";
		}
	}

	public static final ColumnType convertStringToType(String typeForColumn)
	{
		if (typeForColumn.equals("int"))
		{
			return ColumnType.INT;
		}
		else if (typeForColumn.equals("real"))
		{
			return ColumnType.REAL;
		}
		else if (typeForColumn.equals("string"))
		{
			return ColumnType.STRING;
		}
		else if (typeForColumn.equals("date"))
		{
			return ColumnType.DATE;
		}
		else if (typeForColumn.equals("long"))
		{
			return ColumnType.LONG;
		}
		else if (typeForColumn.equals("raw"))
		{
			return ColumnType.RAW;
		}
		else if (typeForColumn.equals("largestring"))
		{
			return ColumnType.LARGESTRING;
		}
		else
		{
			return null;
		}
	}

	public static final String commentizeString(String text)
	{
		return text.replaceAll("^", "#").replaceAll(sNewLine, sNewLine + "#");
	}

	public static final Point getWorkbenchSize()
	{
		return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getSize();
	}

	public static final int computeSubWidth(int halving, int composites)
	{
		Point shellSize = AdapletConstants.getWorkbenchSize();
		int shellWidth = shellSize.x;

		return shellWidth / (2 * halving) - (25 * composites);
	}

	public static String toSQLFormat(String curAttr)
	{
		String temp = curAttr.replaceAll(" ", "_");
		temp = temp.toUpperCase();

		return temp.substring(0, temp.length() >= 30 ? 30 : temp.length());
	}
}
